package com.example.demo.Uilt;

import java.io.File;

public class Uilt {
    public static void deleteTmsFile(double lng, double lat, int zoom, String path, String projectName) {
        int zoomImage = (int) Math.ceil(zoom);
        int tmsx = (int) ((lng + 180) / 360 * Math.pow(2, zoomImage));
        double latRad = lat * Math.PI / 180;
        int tmsy = (int) ((Math.pow(2, zoomImage)) - ((1 - Math.log(Math.tan(latRad) + 1 / Math.cos(latRad)) / Math.PI) / 2 * Math.pow(2, zoomImage)));

        String fileName = (zoom >= 18)
                ? (String.format("%08d", tmsx) + "_" + String.format("%08d", tmsy) + ".png")
                : (String.format("%06d", tmsx) + "_" + String.format("%06d", tmsy) + ".png");


        String folderPath = path + "\\" + projectName + "_" + String.format("%02d", zoom);
        File folder = new File(folderPath);
        File[] files = folder.listFiles();
        for (File file : files) {
            if (file.isDirectory()) {
                String imagePath = file.getPath() + "\\" + fileName;
                File imageFile = new File(imagePath);
                if (imageFile.exists()) {
                    imageFile.delete();
                    System.out.println("删除了文件:"+imagePath);
                }
            }
        }
    }
}
